Consider the problem:

$$ \left.\begin{array}{rrcl} \max & z = 5x_1 + 4.5x_2 + 6x_3\\ \text {s.t.:} & & & \\ & 6x_1 +5x_2 +8x_3 \leq 60\\ & 10x_1 +20x_2 +10x_3 \leq 150 \\ & x_1 \leq 8\\ & x_1,x_2,x_3 \geq 0 \end{array}\right\} $$

In [3]:
using JuMP
m = Model()
# Define variable
@variable(m, x[1:3] >= 0)

@constraints m begin 
     6x[1] +  5x[2] +  8x[3] <= 60
    10x[1] + 20x[2] + 10x[3] <= 150
      x[1]                   <= 8
end

@objective(m, Max, 5x[1] + 4.5x[2] + 6x[3])
print(m)


Max 5 x[1] + 4.5 x[2] + 6 x[3]
Subject to
 6 x[1] + 5 x[2] + 8 x[3] <= 60
 10 x[1] + 20 x[2] + 10 x[3] <= 150
 x[1] <= 8
 x[i] >= 0 for all i in {1,2,3}

PART A

Find the optimal solution.


In [5]:
solve(m)
println("Optimal Profit: ", getobjectivevalue(m))
println("Optimal Solution: ", getvalue(x))


Optimal Profit: 51.42857142857143
Optimal Solution: [6.42857,4.28571,0.0]

In [6]:
writeLP(m, "problem4.lp")

Chainging kernet to python


In [1]:
!less problem4.lp


Maximize
 obj: 5 VAR1 + 4.5 VAR2 + 6 VAR3
Subject To
 c1: 6 VAR1 + 5 VAR2 + 8 VAR3 <= 60
 c2: 10 VAR1 + 20 VAR2 + 10 VAR3 <= 150
 c3: 1 VAR1 <= 8
Bounds
 0 <= VAR1 <= +inf
 0 <= VAR2 <= +inf
 0 <= VAR3 <= +inf
General
End

In [2]:
!glpsol --cpxlp problem4.lp --ranges problem4.sen


GLPSOL: GLPK LP/MIP Solver, v4.60
Parameter(s) specified in the command line:
 --cpxlp problem4.lp --ranges problem4.sen
Reading problem data from 'problem4.lp'...
3 rows, 3 columns, 7 non-zeros
12 lines were read
GLPK Simplex Optimizer, v4.60
3 rows, 3 columns, 7 non-zeros
Preprocessing...
2 rows, 3 columns, 6 non-zeros
Scaling...
 A: min|aij| =  5.000e+00  max|aij| =  2.000e+01  ratio =  4.000e+00
GM: min|aij| =  7.477e-01  max|aij| =  1.337e+00  ratio =  1.789e+00
EQ: min|aij| =  5.590e-01  max|aij| =  1.000e+00  ratio =  1.789e+00
Constructing initial basis...
Size of triangular part is 2
*     0: obj =  -0.000000000e+00 inf =   0.000e+00 (3)
*     4: obj =   5.142857143e+01 inf =   0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.0 Mb (40428 bytes)
Write sensitivity analysis report to 'problem4.sen'...

In [3]:
!less problem4.sen


GLPK 4.60 - SENSITIVITY ANALYSIS REPORT                                                                         Page   1

Problem:    
Objective:  obj = 51.42857143 (MAXimum)

   No. Row name     St      Activity         Slack   Lower bound       Activity      Obj coef  Obj value at Limiting
                                          Marginal   Upper bound          range         range   break point variable
------ ------------ -- ------------- ------------- -------------  ------------- ------------- ------------- ------------
     1 c1           NU      60.00000        .               -Inf       37.50000       -.78571      33.75000 VAR1
                                            .78571      60.00000       65.50000          +Inf      55.75000 c3

     2 c2           NU     150.00000        .               -Inf      128.00000       -.02857      50.80000 c3
                                            .02857     150.00000      240.00000          +Inf      54.00000 VAR1

     3 c3           BS       6.42857       1.57143          -Inf         .            -.36364      49.09091 VAR3
                                            .            8.00000       10.00000        .40000      54.00000 c2

GLPK 4.60 - SENSITIVITY ANALYSIS REPORT                                                                         Page   2

Problem:    
Objective:  obj = 51.42857143 (MAXimum)

   No. Column name  St      Activity      Obj coef   Lower bound       Activity      Obj coef  Obj value at Limiting
                                          Marginal   Upper bound          range         range   break point variable
------ ------------ -- ------------- ------------- -------------  ------------- ------------- ------------- ------------
     1 VAR1         BS       6.42857       5.00000        .                -Inf       4.63636      49.09091 VAR3
                                            .               +Inf        8.00000       5.40000      54.00000 c2

     2 VAR2         BS       4.28571       4.50000        .             2.40000       4.16667      50.00000 c2
                                            .               +Inf        5.45455       6.50000      60.00000 VAR3

     3 VAR3         NL        .            6.00000        .            -1.00000          -Inf      52.00000 c3
                                           -.57143          +Inf        4.09091       6.57143      49.09091 VAR1

End of report

PART B

Suppose that the first two constraints are changed from linear inequalities into equality constraints. What is the change in the optimal solution value? Try figuring out the correct answer first. You may solve the LP again to verify whether your initial answer was correct.

Answer: Both the constraint are used to find the optimal solution. So neither the optimal solution nor the value will change if we chage inequalties to equality constraints.

PART C

Suppose that the first constraint of the original problem is multiplied by two. That is, we modify the first constraint so that it is $12x_1+10x_2+16x_3≤120$. Which of the following statements is correct? (Try to determine the correct answer first via direct reasoning. Subsequently, you can solve the problem again and generate a new sensitivity report).

Answer: The optimal solution and value will not change but the shadow price shoud change by a factor of 1/2.

PART D

Let $P$ denote the model from PART B in which we have changed the first two constraints into equality constraints. Let $Q$ denote the model in which we change the second constraint, but keep all other variables and constraints unchanged. In $Q$, we replace the constraint: $10x_1+20x_2+10x_3=150$ by the constraint $16x_1+25x_2+18x_3=210$. That is, we replace the second constraint from P by the sum of the first two constraints. Problem $Q$ is equivalent to Problem $P$ in the sense that it has the same optimal solution and the same optimal objective value. However, you will find that the shadow prices for $P$ and $Q$ are different. Let $p_1,p_2,p_3$ denote the shadow prices for Problem $P$. Let $q_1,q_2,q_3$ be the shadow prices Problem $Q$. Which of the following answers is correct? You may solve Problem Q and generate the sensitivity report to determine your answer. The correct answer will likely be surprising. See if you can reason through why it is correct.


In [3]:
using JuMP
P = Model()
# Define variable
@variable(P, x[1:3] >= 0)

@constraints P begin 
     6x[1] +  5x[2] +  8x[3] == 60
    10x[1] + 20x[2] + 10x[3] == 150
      x[1]                   <= 8
end

@objective(P, Max, 5x[1] + 4.5x[2] + 6x[3])
writeLP(P, "problem4-p.lp")
print(P)


Max 5 x[1] + 4.5 x[2] + 6 x[3]
Subject to
 6 x[1] + 5 x[2] + 8 x[3] == 60
 10 x[1] + 20 x[2] + 10 x[3] == 150
 x[1] <= 8
 x[i] >= 0 for all i in {1,2,3}

In [4]:
using JuMP
Q = Model()
# Define variable
@variable(Q, x[1:3] >= 0)

@constraints Q begin 
     6x[1] +  5x[2] +  8x[3] == 60
    16x[1] + 25x[2] + 18x[3] == 210
      x[1]                   <= 8
end

@objective(Q, Max, 5x[1] + 4.5x[2] + 6x[3])
writeLP(Q, "problem4-q.lp")
print(Q)


Max 5 x[1] + 4.5 x[2] + 6 x[3]
Subject to
 6 x[1] + 5 x[2] + 8 x[3] == 60
 16 x[1] + 25 x[2] + 18 x[3] == 210
 x[1] <= 8
 x[i] >= 0 for all i in {1,2,3}

In [1]:
!glpsol --cpxlp problem4-p.lp --ranges problem4-p.sen


GLPSOL: GLPK LP/MIP Solver, v4.60
Parameter(s) specified in the command line:
 --cpxlp problem4-p.lp --ranges problem4-p.sen
Reading problem data from 'problem4-p.lp'...
3 rows, 3 columns, 7 non-zeros
12 lines were read
GLPK Simplex Optimizer, v4.60
3 rows, 3 columns, 7 non-zeros
Preprocessing...
2 rows, 3 columns, 6 non-zeros
Scaling...
 A: min|aij| =  5.000e+00  max|aij| =  2.000e+01  ratio =  4.000e+00
GM: min|aij| =  7.477e-01  max|aij| =  1.337e+00  ratio =  1.789e+00
EQ: min|aij| =  5.590e-01  max|aij| =  1.000e+00  ratio =  1.789e+00
Constructing initial basis...
Size of triangular part is 1
      0: obj =   4.500000000e+01 inf =   3.965e+00 (1)
      1: obj =   4.909090909e+01 inf =   0.000e+00 (0)
*     2: obj =   5.142857143e+01 inf =   0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.0 Mb (40428 bytes)
Write sensitivity analysis report to 'problem4-p.sen'...

In [2]:
!glpsol --cpxlp problem4-q.lp --ranges problem4-q.sen


GLPSOL: GLPK LP/MIP Solver, v4.60
Parameter(s) specified in the command line:
 --cpxlp problem4-q.lp --ranges problem4-q.sen
Reading problem data from 'problem4-q.lp'...
3 rows, 3 columns, 7 non-zeros
12 lines were read
GLPK Simplex Optimizer, v4.60
3 rows, 3 columns, 7 non-zeros
Preprocessing...
2 rows, 3 columns, 6 non-zeros
Scaling...
 A: min|aij| =  5.000e+00  max|aij| =  2.500e+01  ratio =  5.000e+00
GM: min|aij| =  8.190e-01  max|aij| =  1.221e+00  ratio =  1.491e+00
EQ: min|aij| =  6.708e-01  max|aij| =  1.000e+00  ratio =  1.491e+00
Constructing initial basis...
Size of triangular part is 1
      0: obj =   4.500000000e+01 inf =   2.982e+00 (1)
      1: obj =   4.909090909e+01 inf =   0.000e+00 (0)
*     2: obj =   5.142857143e+01 inf =   0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.0 Mb (40428 bytes)
Write sensitivity analysis report to 'problem4-q.sen'...

In [3]:
!less problem4-p.sen


GLPK 4.60 - SENSITIVITY ANALYSIS REPORT                                                                         Page   1

Problem:    
Objective:  obj = 51.42857143 (MAXimum)

   No. Row name     St      Activity         Slack   Lower bound       Activity      Obj coef  Obj value at Limiting
                                          Marginal   Upper bound          range         range   break point variable
------ ------------ -- ------------- ------------- -------------  ------------- ------------- ------------- ------------
     1 c1           NS      60.00000        .           60.00000       37.50000          -Inf      33.75000 VAR1
                                            .78571      60.00000       65.50000          +Inf      55.75000 c3

     2 c2           NS     150.00000        .          150.00000      128.00000          -Inf      50.80000 c3
                                            .02857     150.00000      240.00000          +Inf      54.00000 VAR1

     3 c3           BS       6.42857       1.57143          -Inf         .            -.36364      49.09091 VAR3
                                            .            8.00000        6.42857          +Inf          +Inf

GLPK 4.60 - SENSITIVITY ANALYSIS REPORT                                                                         Page   2

Problem:    
Objective:  obj = 51.42857143 (MAXimum)

   No. Column name  St      Activity      Obj coef   Lower bound       Activity      Obj coef  Obj value at Limiting
                                          Marginal   Upper bound          range         range   break point variable
------ ------------ -- ------------- ------------- -------------  ------------- ------------- ------------- ------------
     1 VAR1         BS       6.42857       5.00000        .                -Inf       4.63636      49.09091 VAR3
                                            .               +Inf        6.42857          +Inf          +Inf

     2 VAR2         BS       4.28571       4.50000        .             4.28571          -Inf          -Inf
                                            .               +Inf        5.45455       6.50000      60.00000 VAR3

     3 VAR3         NL        .            6.00000        .            -1.00000          -Inf      52.00000 c3
                                           -.57143          +Inf        4.09091       6.57143      49.09091 VAR1

End of report

In [4]:
!less problem4-q.sen


GLPK 4.60 - SENSITIVITY ANALYSIS REPORT                                                                         Page   1

Problem:    
Objective:  obj = 51.42857143 (MAXimum)

   No. Row name     St      Activity         Slack   Lower bound       Activity      Obj coef  Obj value at Limiting
                                          Marginal   Upper bound          range         range   break point variable
------ ------------ -- ------------- ------------- -------------  ------------- ------------- ------------- ------------
     1 c1           NS      60.00000        .           60.00000       42.00000          -Inf      37.80000 VAR1
                                            .75714      60.00000       64.40000          +Inf      54.76000 c3

     2 c2           NS     210.00000        .          210.00000      188.00000          -Inf      50.80000 c3
                                            .02857     210.00000      300.00000          +Inf      54.00000 VAR1

     3 c3           BS       6.42857       1.57143          -Inf         .            -.36364      49.09091 VAR3
                                            .            8.00000        6.42857          +Inf          +Inf

GLPK 4.60 - SENSITIVITY ANALYSIS REPORT                                                                         Page   2

Problem:    
Objective:  obj = 51.42857143 (MAXimum)

   No. Column name  St      Activity      Obj coef   Lower bound       Activity      Obj coef  Obj value at Limiting
                                          Marginal   Upper bound          range         range   break point variable
------ ------------ -- ------------- ------------- -------------  ------------- ------------- ------------- ------------
     1 VAR1         BS       6.42857       5.00000        .                -Inf       4.63636      49.09091 VAR3
                                            .               +Inf        6.42857          +Inf          +Inf

     2 VAR2         BS       4.28571       4.50000        .             4.28571          -Inf          -Inf
                                            .               +Inf        5.45455       6.50000      60.00000 VAR3

     3 VAR3         NL        .            6.00000        .            -1.00000          -Inf      52.00000 c3
                                           -.57143          +Inf        4.09091       6.57143      49.09091 VAR1

End of report

$p_1 = .78571$ and $p_2 = .02857$ Also, $q_1 = .75714$ and $q_2 = .02857$

EXPLANATION

$q_1=p_1−p_2;q_2=p_2;q_3=p_3.$

Here is one way of figuring it out. Suppose that we consider $p_1$. This is the increase in the optimal objective value of $P$ if we increase the RHS of the first constraint from 60 to 61 and leave all other data unchanged. If we were to make this change in $P$, to get an equivalent change in $Q$, we need to change the RHS of the first constraint of $Q$ to 61, AND we would need to change the RHS of the second constraint of $Q$ to 211. Thus $p_1=q_1+q_2$.

Now consider $p_2$. This is the increase in the optimal objective value of $P$ if we increase the RHS of the second constraint from 150 to 151 and leave all other data unchanged. If we were to make this change in problem $P$, to get an equivalent change in $Q$, we would need to change the RHS of the second constraint of $Q$ to 211. Thus $p_2=q_2$. We now substitute $p_2$ for $q_2$ in the equality $p_1=q_1+q_2$, and obtain $q_1=p_1−p_2$.


In [ ]: